package component.untils
{
	public class SerializeUIXML
	{
		public function SerializeUIXML()
		{
		}
		
		/**
		 * 创建UI XML
		 * @param cItem
		 * @param itemNode
		 * @param curXml 
		 */		
		public static function createXML(cItem:ComponentItem,curXml:XML) : void
		{
			if(!cItem) return;
			
			var itemXML : XML;
			
			for(var i:int=0;i<cItem.childs.length;i++)
			{
				var child:ComponentItem = cItem.childs[i];
				
				if(child.item)
				{	
					itemXML = getComponentItemXML(child);
					
					curXml.appendChild(itemXML);
					
					if(child.childs.length > 0)
					{	
						createXML(child,itemXML);
					}
				}
			}
		}
		
		/**
		 * 获取组建对应的XML
		 * @param item
		 * @return  
		 */		
		private static function getComponentItemXML(comItem : ComponentItem) : XML
		{
			var item : * = comItem.item;
			var itemXML : XML;
			var componentXMLApataer : ComponentXMLAdapter = new ComponentXMLAdapter;
			
			componentXMLApataer.target = comItem;
			itemXML =componentXMLApataer.getXML();
			
			var name : String = item.toString().replace("[object ","");
			name = name.replace("]","");
			
			itemXML.setLocalName(name);
			itemXML.@x = item.x;
			itemXML.@y = item.y;
			itemXML.@width = item.width;
			itemXML.@height = item.height;
			itemXML.@name = item.name;
			
			if(comItem.textFormatName && comItem.textFormatName!="null")
			{
				itemXML.@TextFormat = comItem.textFormatName;
			}
			if(comItem.filterName)
			{
				itemXML.@filterName = comItem.filterName;
			}
			
			componentXMLApataer.destory();
			
			return itemXML;
		}
	}
}